package com.luocj.muke.demo.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.luocj.muke.demo.R;

import java.util.HashMap;


/**
 * Created by renzhiqiang on 16/8/13.
 */
public class TipsDialog extends Dialog implements View.OnClickListener {

    private Context mContext;
    private DisplayMetrics dm;
    private TextView title;


    public TipsDialog(Context context) {
        super(context, R.style.SheetDialogStyle);
        mContext = context;
        dm = mContext.getResources().getDisplayMetrics();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_common_layout);
        initView();
    }

    private void initView() {
        /**
         * 通过获取到dialog的window来控制dialog的宽高及位置
         */
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
//        lp.width = dm.widthPixels; //设置宽度
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        title = findViewById(R.id.title);
        title.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.title:
                onCancelBtnClickListener.OnCancelClicked();
                break;
        }
    }
    public interface OnCancelBtnClickListener{
        void OnCancelClicked();
    }

    private OnCancelBtnClickListener onCancelBtnClickListener;

    public void setOnCancelBtnClickListener(OnCancelBtnClickListener onCancelBtnClickListener) {
        this.onCancelBtnClickListener = onCancelBtnClickListener;
    }
}
